import './index.scss';
import {Form,Input,Button, message} from 'antd';
import {useNavigate} from 'react-router-dom';
import http from '../../utils/http';
import store from '../../store';
import {observer} from 'mobx-react';
const Login =()=>{
    const {Role} = store;
    const navigate = useNavigate();
    // 获取表单内容进入主页面
    const onFinish =(values)=>{
        http({url: `/empl/login`,params:{username:values.username,pwd:values.password},method:'POST'})
        .then(data=>{
            console.log(data);
            if(data.code === 200){
                let obj = {
                    'rolename':data.data.rolename,
                    'role_status':data.data.role_status,
                    'username':data.data.username
                }
                let arr = [...data.data.menu_urls]
                sessionStorage.setItem('token',data.data.token);
                sessionStorage.setItem('power',JSON.stringify(arr));
                sessionStorage.setItem('oneMenu',JSON.stringify(data.data.p_id));
                sessionStorage.setItem('userInfo',JSON.stringify(obj));
                Role.getOneMenu();
                navigate('/home');
            }else if(data.code===50035){
                message.warning('冻结用户不能登录');
            }else{
                message.error('请输入正确的密码或账户名');
            }
        })
    }
    return <div className='dl_login'>
        <div className='dl_formCss'>
            <h1 className='dl_h1'>早教运营后台管理平台</h1>
            <h1 className='dl_h1'>登录</h1>
            <Form name="basic" className='dl_neiForm'
            labelCol={{ span: 5 }}
            wrapperCol={{ span: 14 }}
            onFinish={onFinish} autoComplete="off"
            style={{color:'white'}}>
                <Form.Item
                    label="用户名"
                    name="username"
                    rules={[{ required: true, message: '请输入您的用户名！' }]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="密码"
                    name="password"
                    rules={[{ required: true, message: '请输入您的密码！' }]}
                >
                    <Input.Password />
                </Form.Item>
                <Form.Item wrapperCol={{ offset: 10, span: 10 }}>
                    <Button type="primary" htmlType="submit" size='middle'> 登录 </Button>
                </Form.Item>
            </Form>
        </div>
    </div>
}
export default observer(Login) 